package com.daxue.dynamicloading.service.grpc;

import com.daxue.lcm.api.grpc.interfaces.dynamicloading.ConfigReadByTypeParam;
import com.daxue.lcm.api.grpc.interfaces.dynamicloading.DynamicLoadingServiceGrpc.DynamicLoadingServiceImplBase;
import com.daxue.lcm.api.grpc.interfaces.models.CommonParams;
import com.daxue.lcm.api.grpc.interfaces.models.ResponseMessage;
import com.daxue.lcm.api.grpc.interfaces.models.ResponseMessage.ResponseBody;

import io.grpc.stub.StreamObserver;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * @author daxue0929
 * @date 2022/10/9
 */

@GrpcService
@RequiredArgsConstructor
public class DynamicLoadingGrpcServiceImpl extends DynamicLoadingServiceImplBase {

    // 连接数据库的一个服务
    private final Object configService;


    @Override
    public void configRead(CommonParams.ModelReadParams request, StreamObserver<ResponseBody> responseObserver) {
        ResponseBody.Builder builder = ResponseBody.newBuilder()
            .setTotal(0);
        builder.setContent(null);

        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }

    @Override
    public void configReadByCode(CommonParams.ModelReadByCodeParams request, StreamObserver<ResponseMessage.ResponseBody> responseObserver) {
        ResponseBody.Builder builder = ResponseBody.newBuilder().setTotal(1);

        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }

    @Override
    public void configReadByType(ConfigReadByTypeParam request, StreamObserver<ResponseMessage.ResponseBody> responseObserver) {
        ResponseBody.Builder builder = ResponseBody.newBuilder().setTotal(0);


        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }
}
